/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

/**
 * <p>Project: javase - Img2
 * <p>Powered by webrx On 2021-12-17 09:52:32
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img2 {
    public static void main(String[] args) throws Exception {
        int w = 600;
        int h = 480;
        var img = new BufferedImage(w, h, 2);
        var g = img.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        var r = new Random();
        for (int i = 0; i <= 50; i++) {
            int x = r.nextInt(w);
            int y = r.nextInt(h);
            int ww = r.nextInt(100) + 20;
            int hh = r.nextInt(100) + 20;
            int num = r.nextInt(3);
            var c = switch (num) {
                case 0 -> new Color(0xff, 0, 0, r.nextInt(100) + 50);
                case 1 -> new Color(0, 0xff, 0, r.nextInt(100) + 50);
                default -> new Color(0, 0, 0xff, r.nextInt(100) + 50);
            };
            g.setColor(c);
            g.fillOval(x, y, ww, hh);
        }

        var red = Color.RED;
        g.setColor(red);

        //控制字体 大小
        //Font font = new Font("经典行书简", Font.PLAIN, 50);


        //font = Font.createFonts( new File("zh164hfyh.woff"))[0];
        //Font font = Font.createFonts(Font.TYPE1_FONT, new File("zh164hfyh.woff"));

        //g.setFont(font);
        g.drawString("中文文字效果", 200, 50);

        g.dispose();

        ImageIO.write(img, "png", new File("c:/ok.png"));
        Runtime.getRuntime().exec("cmd /k start c:/ok.png");
    }
}
